package cn.lichenfei.jfx.music.gui;

import cn.lichenfei.jfx.music.Application;
import cn.lichenfei.jfx.music.common.Config;
import cn.lichenfei.jfx.music.common.utils.JFUtils;
import javafx.scene.control.Button;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.Priority;
import javafx.stage.Stage;
import org.kordamp.ikonli.antdesignicons.AntDesignIconsFilled;
import org.kordamp.ikonli.antdesignicons.AntDesignIconsOutlined;
import org.kordamp.ikonli.javafx.FontIcon;

/**
 * @author ChenFei
 * @date 2022/4/21
 */
public class MusicPane extends Pane {

    private MusicList musicList = new MusicList();
    private MusicHome musicHome = new MusicHome();

    public MusicList getMusicList() {
        return musicList;
    }

    public MusicHome getMusicHome() {
        return musicHome;
    }

    {
        this.getStylesheets().addAll(Application.class.getResource("css/music-pane.css").toExternalForm());
        this.getChildren().addAll(musicHome, musicList);
        this.getStyleClass().add("music-pane");
        musicHome.getStyleClass().add("music-home");
        musicList.getStyleClass().add("music-list");
    }

    private HBox topBox = new HBox();
    private HBox topLeftBox = new HBox();
    private HBox topRightBox = new HBox();
    //最小化，关闭窗口按钮
    private Button onTopBut = new Button();
    private Button hideBut = new Button();
    private Button closeBut = new Button();

    {
        this.getChildren().add(topBox);
        topBox.getChildren().addAll(topLeftBox, topRightBox);
        topBox.setHgrow(topLeftBox, Priority.ALWAYS);
        topRightBox.getChildren().addAll(onTopBut, hideBut, closeBut);
        onTopBut.setGraphic(new FontIcon(AntDesignIconsFilled.PUSHPIN));
        hideBut.setGraphic(new FontIcon(AntDesignIconsOutlined.MINUS));
        closeBut.setGraphic(new FontIcon(AntDesignIconsOutlined.CLOSE));
        topBox.getStyleClass().add("top-box");
        topRightBox.getStyleClass().add("top-right-box");
        onTopBut.getStyleClass().add("on-top-but");
        hideBut.getStyleClass().add("hide-but");
        closeBut.getStyleClass().add("close-but");
        hideBut.setOnMouseClicked(event -> JFUtils.setIconified(event.getSource(), true));
        closeBut.setOnMouseClicked(event -> {
            //记录当前播放音乐，音量，播放的时间
            Config.storeSetting();
            JFUtils.hideCurrentWindow(event.getSource());
        });
        //窗口是否展示在顶部
        onTopBut.setOnMouseClicked(event -> {
            Stage stage = (Stage) onTopBut.getParent().getScene().getWindow();
            boolean onTop = stage.isAlwaysOnTop();
            stage.setAlwaysOnTop(!onTop);
            if (onTop) {
                onTopBut.setStyle("-fx-background-color:#909399;");
            } else {
                onTopBut.setStyle("-fx-background-color:#67C23A;");
            }
        });
    }


    public MusicPane() {

    }

}
